<?php
/**
 * pemilu
 * copyright (c) 2013 abie
 *
 * @author abie
 * @date 12/20/13 1:19 AM
 */

abstract class MyModel extends CModel {

    /**
     * @return string[]
     */
    abstract protected function getAllKeys();

    public function findAll($condition = null) {
        $result = array();
        foreach ($this->getAllKeys() as $pk) {
            $item = $this->findByPk($pk);
            $masuk = true;
            if ($condition) {
                foreach ($condition as $key => $val) {
                    if ($item->$key != $val)
                        $masuk = false;
                }
            }
            if ($masuk)
                $result[] = $item;
        }
        return $result;
    }

    /**
     * @param $pk
     * @return MyModel
     */
    abstract public function findByPk($pk);

    /**
     * Returns the list of attribute names of the model.
     *
     * @return array list of attribute names.
     */
    public function attributeNames()
    {
        // TODO: Implement attributeNames() method.
    }}